//
//  GDHomeViewController.m
//  美团试验 (自己)
//
//  Created by 热带雨林 on 17/2/12.
//  Copyright © 2017年 热带雨林. All rights reserved.
//

#import "GDHomeViewController.h"
#import "Masonry.h"
#import "GDMainViewController.h"
#import <UserNotifications/UserNotifications.h>

@interface GDHomeViewController ()

@end

@implementation GDHomeViewController

- (void)viewDidAppear:(BOOL)animated{
    [super  viewDidAppear:animated];
//    self.navigationController.navigationBar.alpha = 0;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    self.view.backgroundColor = [UIColor redColor];
    
}

- (void)setupUI{
    
    NSDictionary *firstVC = @{@"vcName":@"GDNewsViewController",@"imageName":@"news"};
    NSDictionary *secoundVC = @{@"vcName":@"GDMainViewController",@"imageName":@"found"};
    NSDictionary *thirdVC = @{@"vcName":@"GDBarViewController",@"imageName":@"bar"};
 
    NSDictionary *fourthVC = @{@"vcName":@"GDMeViewController",@"imageName":@"me"};
    
    UIViewController *firstV = [self addViewControllerWithInfor:firstVC];
    UIViewController *secoundV = [self addViewControllerWithInfor:secoundVC];
    UIViewController *thirdV = [self addViewControllerWithInfor:thirdVC];
    UIViewController *fourthV = [self addViewControllerWithInfor:fourthVC];

    self.viewControllers = @[firstV,secoundV,thirdV,fourthV];
    
    firstV.tabBarItem.title = @"新闻";
    secoundV.tabBarItem.title = @"美食";
    thirdV.tabBarItem.title = @"其他";
    fourthV.tabBarItem.title = @"账号";
    
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self  selector:@selector(notification) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop]addTimer:timer forMode:UITrackingRunLoopMode];
}

//开始添加子控制器
- (UIViewController *)addViewControllerWithInfor:(NSDictionary *)dic{
    Class cla = NSClassFromString(dic[@"vcName"]);
    UIViewController *VC = [[cla alloc]init];
    VC.tabBarItem.image = [[UIImage imageNamed:[NSString stringWithFormat:@"tabbar_icon_%@_normal",dic[@"imageName"]]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    VC.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"tabbar_icon_%@_highlight",dic[@"imageName"]]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:VC];
    
    return navi;
}
//本地推送
- (void)notification{
    UILocalNotification *notification = [[UILocalNotification alloc]init];
    notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
    notification.alertBody = @"爱新奇－您有一条新消息";
    notification.soundName = UILocalNotificationDefaultSoundName;
    //将创建好的推送通知加入到调度池
    [[UIApplication sharedApplication]scheduleLocalNotification:notification];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
